Page({
  data: {
    showCount:"",
    idData:"",
    pollData:"",
    pollValue:""
  },
  onLoad() {
    this.getPollValue()
  },
  // 当前上传人数
  getPollValue(){
    const { cloud } = getApp();

    cloud.function.invoke('business', {}, 'getUploadWorkPeopleNum').then(res => {

      if(res.code==0){
        console.log("当前上传人数：",res)
       this.setData({
         pollValue:res.data
       })
      }
    })
  },
  // 读取票数输入值
  setPollValue(e){
    console.log(e)
    this.setData({
      pollData:parseInt(e.detail.value)
    })
  },
  // 读取id输入值
  setIdValue(e){
    console.log(e)
    this.setData({
      idData:e.detail.value
    })
  },
  // 读取输入值
  setShowCountValue(e){
    console.log(e)
    this.setData({
      showCount:e.detail.value
    })
  },
  // 修改上传作品人数
  handleChangeShowCount(){
      const { cloud } = getApp();
      if(this.data.showCount==""){
        my.alert({content:"请输入数值再确认哦~"})
        return
      }
    const options = {
      'uploadWorkPeopleNum':parseInt(this.data.showCount) 
    };
    console.log(options)
    cloud.function.invoke('business', options, 'setUploadWorkPeopleNum').then(res => {
      console.log('修改成功'+JSON.stringify(res))
      if(res.code==0){
        this.getPollValue()
        my.alert({
          content:res.msg+",修改后值为:"+res.data
        })
      }
    })
  },

  // 修改作品票数
  handleShowCount(){
          const { cloud } = getApp();
          if(this.data.idData=="" || this.data.pollData==""){
        my.alert({content:"请确认id或票数是否为空哦~"})
        return
      }
      const options = {
        _id:this.data.idData,
        voteNum:parseInt(this.data.pollData)
      };
        cloud.function.invoke('business', options, 'setVoteNum').then(res => {
      console.log('修改成功'+JSON.stringify(res))
      if(res.code==0){
        my.alert({
          content:res.msg+",修改后值为:"+res.data
        })
      }
    })
  },

});
